var member_id = '',ws = goods_id = order_id = uid = ''; 
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	ws = plus.webview.currentWebview();
	goods_id = ws.goods_id;
	var store_id = ws.store_id;
	var purchase = ws.purchase;
	if(purchase == 'purchase'){
		$('.purchase').css('display','none');
		$('.sellout').css('display','block');
	}else if(purchase == 'flea'){
		$('.mui-bar-tab').css('display','none');
	} 
	console.log(apiRoot+"?act=goods&op=index&goods_id="+goods_id+"&flea=1");
	plus.nativeUI.showWaiting('加载中...');
	$.ajax({ 
		type:"get", 
		url:apiRoot+"?act=goods&op=index&goods_id="+goods_id+"&flea=1",
		dataType:'json',  
		success:function(data){ 
			console.log(JSON.stringify(data));
			if(data){
				if(data.goods_info){
					uid = data.member_info.member_id;
					$('.tel').attr('data-tel',data.member_info.member_mobile);
					$('.goods_name').text(data.goods_info.goods_name);
					$('.red').text('￥' + data.goods_info.goods_price);  
					$('.mui-ellipsis-2').text(data.goods_info.goods_jingle);			
					$('.member_name').text((data.member_info.member_truename?data.member_info.member_truename:data.member_info.member_name));    
					$('.Flimg').html(data.goods_info.mobile_body); 
					$('.member_avatar').attr('src',(data.member_info.member_avatar?(user_pic + data.member_info.member_avatar):''));
					$('.goods_id').attr('data-goods_id',data.goods_info.goods_id);
					$('.goods_id').attr('data-store_id',data.goods_info.store_id);
				}
				if(data.goods_images){
					var count = 0;
					$.each(data.goods_images, function(k,v) {
						count = count + 1;
						var html = '<img src="'+ pics + data.goods_info.store_id + '/' + v.goods_image +'" data-preview-src="" data-preview-group="1"/>';
						$('.mui-text-center').prepend(html);
					});  
					$('.count').text('1/'+count);
				} 
			}
			$('.goumai').on('click',function(){
				var shuju = data.goods_info.goods_id+'|1';
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./goods.html','goods.html',{},{shuju:shuju,store_id:data.goods_info.store_id,payment_type:'online',ifcart:0,flea:'flea',uid:uid});//flea 跳蚤商品
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
				}, false);
			})
			plus.nativeUI.closeWaiting();
		}, 
		error:function(e){
//			console.log(JSON.stringify(e));
			plus.nativeUI.closeWaiting();
			toast('连接失败！');
		}
	});
},false);